//
//  HFTiXianTFCell.m
//  APPStart
//
//  Created by 慧鼎科技 on 2018/11/10.
//  Copyright © 2018 WQ. All rights reserved.
//

#import "HFTiXianTFCell.h"
//#import "WqGaoDeLocationViewController.h"

#import "BaseNavViewController.h"
#import <CoreLocation/CoreLocation.h>
#import "MBProgressHUD.h"
@interface HFTiXianTFCell ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;

@end

@implementation HFTiXianTFCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _contentTF.delegate = self;
    [_contentTF addTarget:self action:@selector(inputContentClick:) forControlEvents:(UIControlEventEditingDidEnd)];
    
    [_contentTF addTarget:self action:@selector(inputContentClending:) forControlEvents:(UIControlEventEditingDidBegin)];
    
    UIButton *bug = [UIButton buttonWithType:(UIButtonTypeCustom)];
    self.selebut = bug;
    bug.frame = self.contentTF.frame;
    [self.contentView addSubview:bug];
    [bug addTarget:self action:@selector(dsffdsfdsfsd) forControlEvents:(UIControlEventTouchUpInside)];
    
    self.selebut.hidden = YES;
}
-(void)dsffdsfdsfsd{
    if (self.inputContentBlock) {
        self.inputContentBlock(@"");
    }
    
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    // Configure the view for the selected state
}


- (void)inputContentClending:(UITextField *)sender {
    if( sender.tag ==777 ){
        if (self.inputContentBlock) {
            self.inputContentBlock(@"");
        }

    }

 
    
}
- (void)inputContentClick:(UITextField *)sender {
    
    if (self.inputContentBlock) {
        self.inputContentBlock(sender.text);
    }
    [sender resignFirstResponder];

}


- (void)configDataWithTitle:(NSString *)title placeHolder:(NSString *)placeHolder content:(NSString *)content {
    
    _titleLabel.text = title;
    _contentTF.placeholder = placeHolder;
  
    if (!strIsEmpty(content)) {
        _contentTF.text = content;
    }
}
//- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField:(UITextField *)textField{
//    NSLog(@"dsfsf%@",_titleLabel.text);
//    if( [_titleLabel.text isEqualToString:@"所在地区"]){
//        if (self.inputContentBlock) {
//            self.inputContentBlock(@"");
//        }
//        return NO;
//        }
//    return YES;
//}
#pragma mark -- 定位服务
-(void)locationAction{
    /*
    KMyLog(@"定位");
    kWeakSelf;
    if ([self isLocationServiceOpen]) {
        WqGaoDeLocationViewController *locaVC = [[WqGaoDeLocationViewController alloc]init];
        BaseNavViewController * navigation = [[BaseNavViewController alloc]initWithRootViewController:locaVC];
        [[UINavigationController new] presentViewController:navigation animated:YES completion:nil];
        locaVC.locaBlock = ^(NSMutableDictionary *locadic) {
            NSLog(@"%@", locadic);
            NSString *info = [NSString stringWithFormat:@"{\"text\":\"%@\",\"location\":\"%@,%@\"}", locadic[@"building_name"], locadic[@"longitude"], locadic[@"latitude"]];
            
            NSString *callBack = [NSString stringWithFormat:@"getLocationCallBack('%@')", info];
            
            //            [weakSelf.webView evaluateJavaScript:callBack completionHandler:nil];
        };
    }else{
        //未开启定位权限
        UIAlertController *alertCon = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"需要您开启定位权限,是否允许" preferredStyle:UIAlertControllerStyleAlert];
        
        [alertCon addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            KMyLog(@"取消");
        }]];
        [alertCon addAction:[UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            KMyLog(@"确定");
            if ([[[UIDevice currentDevice] systemVersion] integerValue] >9.9) {
                
                [[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
                
            } else {
                
                NSURL *url = [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
                
                [[UIApplication sharedApplication] openURL:url];
            }
            
        }]];
        
        
    }
    */
}

//是否开启定位
- (BOOL)isLocationServiceOpen {
    if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied) {
        return NO;
    } else
        return YES;
}

@end
